// common service 创建AbstractBaseService抽象类
package com.kuaidao.common.service;

import com.kuaidao.common.mapper.IBaseCRUD;
import com.kuaidao.common.util.ReflectHelper;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Map;

@Slf4j
public abstract class AbstractBaseService<E, K> implements IBaseService<E, K>  {

    protected Class<E> entityClass;

    protected abstract IBaseCRUD<E, K> getBaseCRUD();


    protected AbstractBaseService() {
        this.entityClass = (Class<E>) ReflectHelper.getSuperClassGenericType(getClass(), 0);
    }

    @Override
    public boolean insert(E entity) {
        return getBaseCRUD().insert(entity);
    }

    @Override
    public boolean update(E entity) {
        return getBaseCRUD().update(entity);
    }

    @Override
    public boolean deleteByPrimaryKey(K primaryKey) {
        return getBaseCRUD().deleteByPrimaryKey(primaryKey);
    }

    @Override
    public boolean deleteBatchByPrimaryKeyList(List<K> keys) {
        return getBaseCRUD().deleteBatchByPrimaryKeyList(keys);
    }

    @Override
    public E findByPrimaryKey(K primaryKey) {
        return getBaseCRUD().findByPrimaryKey(primaryKey);
    }

    @Override
    public List<E> findEntityListByParams(Map paramMap) {
        return getBaseCRUD().findEntityListByParams(paramMap);
    }

}